package com.lbloca.locate.biz;

import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;

import com.lbloca.locate.utils.AppUtils;
import com.lbloca.locate.utils.LogUtils;
import com.lbloca.locate.utils.SPUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

public class AppBiz {
    private static final String TAG = "AppBiz";

    private static AppBiz instance;

    public static AppBiz getInstance() {
        if (instance == null)
            instance = new AppBiz();
        return instance;
    }

    public void register(String phone, StringCallback callback) {
        OkHttpUtils.get().url(Config.URL_REGISTER).addParams("phone", phone).addParams("imei", getDK()).tag(this).build().execute(callback);
    }

    public void putAddress(String address, double lng, double lat, StringCallback callback) {
        OkHttpUtils.get().url(Config.URL_PUT_ADDRESS).addParams("userid", getUid()).addParams("address", address)
                .addParams("jd", lng + "").addParams("wd", lat + "").tag(this).build().execute(callback);
    }

    public void addFriend(String phone, StringCallback callback) {
        OkHttpUtils.get().url(Config.URL_ADD_FRIEND).addParams("userid", getUid()).addParams("phone", phone)
                .tag(this).build().execute(callback);
    }

    public void getFriends(StringCallback callback) {
        LogUtils.i(TAG,getUid());
        OkHttpUtils.get().url(Config.URL_GET_FRIEND).addParams("userid", getUid()).tag(this).build().execute(callback);
    }

    private String getDK() {
        String sn = Settings.Secure.getString(AppUtils.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
        if (TextUtils.isEmpty(sn) || sn.equals("9774d56d682e549c")) {
            sn = Build.SERIAL;
        }
        return sn;
    }

    private String getUid() {
        return UserBiz.getInstance().getUid();
    }


    public  boolean getVipState(){
//        boolean isVip = SPUtils.getInstance().getBoolean(Config.SPF_VIP_STATE,false);

        int vipstate = SPUtils.getInstance().getInt(Config.SPF_VIP_STATE, 0);
        if(vipstate==1){
            return true;
        }
        return false;
    }

}
